package com.aqie.meet.ui.login;

import android.content.Intent;
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;

import com.aqie.libcommon.app.BaseApplication;
import com.aqie.libcommon.app.PresenterActivity;
import com.aqie.libfactory.model.api.user.RegisterModel;
import com.aqie.libfactory.presenter.account.RegisterContract;
import com.aqie.libfactory.presenter.account.RegisterPresenter;
import com.aqie.meet.R;
import com.aqie.meet.utils.ButtonUtils;

import net.qiujuer.genius.ui.widget.Loading;

import butterknife.BindView;
import butterknife.OnClick;

import static com.raizlabs.android.dbflow.config.FlowManager.getContext;

/**
 * 问题 行业 岗位
 */
public class Reg3Activity extends PresenterActivity<RegisterContract.Presenter>
        implements RegisterContract.View {

    @BindView(R.id.bt_register)
    Button mButtonFinish;

    @BindView(R.id.loading)
    Loading mLoading;

    @BindView(R.id.et_answer_one)
    EditText mAnswerOne;

    @BindView(R.id.et_answer_two)
    EditText mAnswerTwo;

    @BindView(R.id.et_answer_three)
    EditText mAnswerThree;

    @BindView(R.id.et_trade)
    EditText mTrade;

    @BindView(R.id.et_position)
    EditText mPosition;

    private String code;
    private String phone;
    private String name;

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_reg3;
    }

    @Override
    protected void initData() {
        super.initData();
        Intent intent = getIntent();
        phone = intent.getStringExtra("phone");
        code = intent.getStringExtra("code");
        name = intent.getStringExtra("username");
        Log.e(TAG, " phone " + phone + " " + code + " " + name);
    }

    @OnClick(R.id.bt_register)
    void doRegister(){
        if  (ButtonUtils.isFastDoubleClick(R.id.bt_register)) {
            //写你相关操作即可
            return;
        }
        // trade position et_answer_three
        String technique = mAnswerThree.getText().toString();
        String trade = mTrade.getText().toString();
        String position = mPosition.getText().toString();
        if(TextUtils.isEmpty(technique)){
            BaseApplication.showToast("知识或技能必填");
            return;
        }
        if(TextUtils.isEmpty(trade) || TextUtils.isEmpty(position)){
            BaseApplication.showToast("行业和岗位必填");
            return;
        }
        RegisterModel model = new RegisterModel();
        model.setAnswerOne(mAnswerOne.getText().toString());
        model.setAnswerTwo(mAnswerTwo.getText().toString());
        model.setAnswerThree(technique);
        model.setPhone(phone);
        model.setUsername(name);
        model.setTrade(trade);
        model.setPosition(position);
        model.setCode(code);
        mPresenter.register(model);
    }

    @Override
    protected RegisterContract.Presenter initPresenter() {
        return new RegisterPresenter(this);
    }

    @Override
    public void registerSuccess() {
        BaseApplication.showToast("完成注册");
        LoginActivity.show(getContext());
        finish();
    }

    @Override
    public void showError(String errMsg) {
        super.showError(errMsg);
        mLoading.stop();
    }

    @Override
    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
        super.onApplyThemeResource(theme, resid, first);
    }



}